package com.scorpio.demo;

import androidx.appcompat.app.AppCompatActivity;
import androidx.core.content.ContextCompat;

import android.os.Bundle;
import android.view.View;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

import com.scorpio.rotatemenu.DensityUtil;
import com.scorpio.rotatemenu.RutateMenuView;
import com.scorpio.rotatemenu.ScorpioEntity;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends AppCompatActivity implements View.OnClickListener, RutateMenuView.OnMenuItemClickListener, RutateMenuView.OnMenuScrollChangedListener {

    private RutateMenuView rutateMenuView;

    private Button button1, button2, addBtn8, addBtn9, iconSizeBtn, maxZoomBtn;

    private TextView output1, output2;

    private EditText iconSize, maxZoom;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        addBtn8 = findViewById(R.id.addBtn8);
        addBtn9 = findViewById(R.id.addBtn9);
        button1 = findViewById(R.id.button1);
        button2 = findViewById(R.id.button2);
        output1 = findViewById(R.id.output1);
        output2 = findViewById(R.id.output2);
        iconSize = findViewById(R.id.iconSize);
        maxZoom = findViewById(R.id.maxZoom);
        iconSizeBtn = findViewById(R.id.iconSizeBtn);
        maxZoomBtn = findViewById(R.id.maxZoomBtn);

        iconSize.setText("" + DensityUtil.dip2px(this, 40));
        maxZoom.setText("" + 0.2f);


        rutateMenuView = findViewById(R.id.rutateMenuView);
        rutateMenuView.setOnMenuItemClickListener(this);
        rutateMenuView.setOnMenuScrollChangedListener(this);
        addBtn8.setOnClickListener(this);
        addBtn9.setOnClickListener(this);
        button1.setOnClickListener(this);
        button2.setOnClickListener(this);
        iconSizeBtn.setOnClickListener(this);
        maxZoomBtn.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        List<ScorpioEntity> list = new ArrayList<>();
        switch (v.getId()) {
            case R.id.addBtn8:
                for (int i = 0; i < 9; i++) {
                    ScorpioEntity entity = new ScorpioEntity(R.drawable.icon_occupied, "菜单" + (i + 1));
                    list.add(entity);
                }
                output1.setText("***");
                output2.setText("***");
                rutateMenuView.setData(list);
                rutateMenuView.setItemAngleInterval(25f);
                break;
            case R.id.addBtn9:
                for (int i = 0; i < 18; i++) {
                    ScorpioEntity entity = new ScorpioEntity(R.drawable.icon_occupied, "菜单" + (i + 1));
                    list.add(entity);
                }
                output1.setText("***");
                output2.setText("***");
                rutateMenuView.setData(list);
                rutateMenuView.setItemAngleInterval(18f);
                break;
            case R.id.button1:
                rutateMenuView.setSelection(1, false);
                break;
            case R.id.button2:
                rutateMenuView.setSelection(4, true);
                break;
            case R.id.iconSizeBtn:
                String iconSizeValue = iconSize.getText().toString();
                rutateMenuView.setIconSize(Integer.valueOf(iconSizeValue));
                break;
            case R.id.maxZoomBtn:
                String maxZoomValue = maxZoom.getText().toString();
                rutateMenuView.setMaxZoom(Float.valueOf(maxZoomValue));
                break;
        }
    }

    @Override
    public void onMenuItemClick(int index) {
        output1.setText("当前点击:index=" + index);
    }

    @Override
    public void onMenuChanged(int index) {
        output2.setText("当前滑动:index=" + index);
    }
}
